package com.example.demo2.mapper;

import com.example.demo2.entity.*;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ProjectMapper {

    @Select("select * from project where pjId=#{pjId}")
    Project findProjectByPjId(@Param("pjId") Integer pjId);

    @Select("select * from project where pjName like #{query} or pjGB like #{query}")
    public List<Project> searchProject(@Param("query") String query);

    @Select("select * from project where staId = #{staId}")
    public List<Project> findAllProjectBysatId(@Param("staId") int staId);

    @Insert("insert into project (pjName , pjGB,staId) values(#{project.pjName}, #{project.pjGB},#{project.staId})")
    public int AddProject(@Param("project") Project project );

    @Delete("delete from project where pjId = #{pjId}")
    public int DeleteOneProject(@Param("pjId") int pjId);

    @Select("select staId from standard where staGB = #{staGB}")
    public int findStaIdByGB(@Param("staGB") String staGB);

    @Insert({
            "<script>",
            "INSERT INTO project(pjName, pjGB, staId) VALUES ",
            "<foreach collection='projects' item='project' separator=','>",
            "(#{project.pjName}, #{project.pjGB}, #{project.staId})",
            "</foreach>",
            "</script>"
    })
    int insertProjectList(@Param("projects") List<Project> projects);




}
